const tree = {
  name: 'root',
  task: () => {
    console.log('root')
  },
  children: [
    {
      name: '一级子树 01',
      task: () => {
        console.log('一级子树 01')
      },
      children: [
        {
          name: '二级子树 01_01',
          task: () => {
            console.log('二级子树 01_01')
          },
          children: [],
        },
        {
          name: '二级子树 01_02',
          task: () => {
            console.log('二级子树 01_02')
          },
          children: [],
        },
      ],
    },
    {
      name: '一级子树 02',
      task: () => {
        console.log('一级子树 02')
      },
    },
  ],
}
const mapTreeToNodeList = (tree) => {
  let root = {
    name: 'god',
  }
  let current = root
  const push = (node) => {
    current = current.next = node
  }
  const foo = (tree) => {
    push(tree)
    if (tree.children) {
      tree.children.forEach((item) => {
        foo(item)
      })
    }
  }
  foo(tree)
  return root
}
const list = mapTreeToNodeList(tree)
console.log(list)
